<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>IT老兵在线聊天室</title>
<!-- 定义上下文路径 -->
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!-- 引入全局样式 -->
<link rel="stylesheet" href="${ctx}/css/style.css"/>
</head>
<body>
<!-- 登录表单 -->
<form name="form1" method="post" action="messages?action=loginRoom" onSubmit="return check()">
    <table width="371" height="230"  border="0" align="center" cellpadding="0" cellspacing="0" background="${ctx}/images/login.jpg">
      <tr>
        <td height="158" colspan="3" class="word_dark">&nbsp;</td>
      </tr>
      <tr>
        <td width="53" align="center" valign="top" class="word_dark">&nbsp;</td>
        <td width="216" align="center" valign="top" class="word_dark">用户名：
<input type="text" name="username" class="login"></td>
        <td width="94" valign="top" class="word_dark"><input name="Submit" type="submit" class="btn_bg" value="进 入"></td>
      </tr>
</table>		
</form>
<script language="javascript">
//登录前校验
function check(){
	//用户名校验正则（只能输入中英文、数字及汉字）
	var pat=new RegExp("[^a-zA-Z0-9\_\u4e00-\u9fa5]","i");
	//去掉输入的用户名中的空格
	form1.username.value = form1.username.value.replace(/\s/g,'');
	//判断用户名是否为空
	if(form1.username.value==""){
		alert("请输入用户名！");form1.username.focus();return false;	
	}else if(pat.test(form1.username.value)){ //判断是否合法
		alert("请不要输入非法字符。(只能输入中英文、数字及汉字)");form1.username.focus();return false;
	}
}
</script>
</body>
</html>